home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993 October: Windmill on DISC / ADC Developer CD (1993-10) (''Windmill On DISC'')_iso / Dev.CD Oct 93.iso / System Software / U.S. System Software / System 7 Pro™ Beta 11 / Development Tools / Sample Code / Standard Mail / CollaboDraw (w⁄DigiSign) / windowstuff.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-11  |  6.0 KB  |  303 lines  |  [TEXT/MPS ]

  1. /*-------------------------------------------------------------------------------------
  2.  *
  3.  * Simple Sample AOCE Application Framework
  4.  *
  5.  * ©1991-1993 Apple Computer
  6.  *
  7.  -------------------------------------------------------------------------------------*/
  8. /*
  9.  * windowstuff.c -- window class instantiation/dispatching
  10.  *
  11.  * change history:
  12.  *
  13.  * SJF        04/21/93        1.0b2        update to b2
  14.  * SJF        03/01/93        1.0b1        added digital signatures
  15.  * SJF        02/09/93        1.0b1        update to b1
  16.  * SJF        10/13/92        1.0d4        update to a11
  17.  * SJF        09/09/92        1.0d3        update to a9
  18.  * SJF        05/07/92        1.0d2        update to a6
  19.  * SJF        11/06/91        1.0d1        initial coding
  20.  *
  21.  */
  22.  
  23. #ifndef __OCESTANDARDMAIL__
  24. #include <OCEStandardMail.h>
  25. #endif
  26.  
  27. #include "const.h"
  28. #include "mytypes.h"
  29. #include "globals.h"
  30. #include "utils.h"
  31.  
  32. #include "base.window.h"
  33. #include "draw.window.h"
  34. #include "draw.mailer.window.h"
  35.  
  36. #include "windowstuff.h"
  37.  
  38. /* gets info handle for a window */
  39.  
  40. WInfoHndl GetWindowInfo(WindowPtr window)
  41. {
  42.     WInfoHndl theInfo;
  43.     
  44.     if (window==nil)
  45.         return nil;
  46.         
  47.     theInfo = (WInfoHndl) GetWRefCon(window);
  48.     return theInfo;
  49. }
  50.  
  51.  
  52. /* sets info handle for a window */
  53.  
  54. void SetWindowInfo(WindowPtr window,WInfoHndl info)
  55. {
  56.     if (window==nil) {
  57.         DoError(kInternalError);
  58.         return;
  59.     }
  60.         
  61.     SetWRefCon (window,(long)info);
  62. }
  63.  
  64.  
  65. /* gets window kind of a given window */
  66.  
  67. WindowKind GetWindowKind(WindowPtr window)
  68. {
  69.     WindowKind wKind;
  70.     
  71.     if (window==nil) {
  72.         DoError(kInternalError);
  73.         return 0;
  74.     }
  75.     wKind = ((WindowPeek)window)->windowKind;
  76.     return wKind;
  77. }
  78.  
  79.  
  80. /* sets window kind of a given window */
  81.  
  82. void SetWindowKind(WindowPtr window,WindowKind wKind)
  83. {
  84.     if (window==nil) {
  85.         DoError(kInternalError);
  86.         return;
  87.     }
  88.  
  89.     ((WindowPeek)window)->windowKind = wKind;
  90. }
  91.  
  92.  
  93. /* checks to see if a window is of a certain type */
  94.  
  95. Boolean IsWindowType(WindowPtr window,WindowKind type)
  96. {
  97.     return (type == GetWindowKind(window));
  98. }
  99.  
  100.  
  101. /* returns true if it's a window created by the application */
  102.  
  103. Boolean IsAppWindow(WindowPtr window)
  104. {
  105.     WindowKind wKind;
  106.     
  107.     if (!window)
  108.         return false;
  109.     
  110.     wKind = GetWindowKind(window);
  111.     return (wKind >= userKind);
  112. }
  113.  
  114.  
  115. /* returns true if the window belongs to a DA */
  116.  
  117. Boolean IsDAWindow(WindowPtr window)
  118. {
  119.     return (GetWindowKind(window) < 0);
  120. }
  121.  
  122.  
  123. /* locks the data area of a window */
  124.  
  125. WInfoPtr BeginWindowAccess(WindowPtr theWindow,char *hState)
  126. {
  127.     WInfoHndl infoHndl;
  128.     
  129.     infoHndl = GetWindowInfo(theWindow);
  130.     *hState = HGetState((Handle) infoHndl);
  131.     MoveHHi((Handle) infoHndl);
  132.     HLock((Handle) infoHndl);
  133.     return *infoHndl;
  134. }
  135.  
  136.  
  137. /* unlocks the data area of a window */
  138.  
  139. void EndWindowAccess(WindowPtr theWindow,char hState)
  140. {
  141.     WInfoHndl infoHndl;
  142.     
  143.     infoHndl = GetWindowInfo(theWindow);
  144.     HSetState((Handle) infoHndl,hState);
  145. }
  146.  
  147.  
  148. /* makes a window of a given type and returns its window pointer */
  149.  
  150. WindowPtr MakeWindow(WindowKind windowClass,Rect *wRect,StringPtr title,Boolean visible)
  151. {
  152.     WindowPtr window,windowLook;
  153.     Rect theRect;
  154.     short expHeight,contHeight,mWidth;
  155.     OSErr err;
  156.     Point offsetWind;
  157.     GrafPtr savePort;
  158.     
  159.     if (wRect==nil)
  160.     {
  161.         if (gHasAOCE) {
  162.             err = SMPGetDimensions(&mWidth,&contHeight,&expHeight);
  163.             if (err!=noErr)
  164.                 DoError(err);
  165.         }
  166.         else mWidth = 492;
  167.         SetRect(&theRect, 20, 50, 20 + mWidth, 340);
  168.         
  169.         GetPort(&savePort);
  170.         windowLook = FrontWindow();
  171.         while (windowLook) {
  172.             SetPt(&offsetWind,0,0);
  173.             SetPort(windowLook);
  174.             LocalToGlobal(&offsetWind);
  175.             if (theRect.top==offsetWind.v && theRect.left==offsetWind.h) {
  176.                 OffsetRect(&theRect,kWindowOffset,kWindowOffset);
  177.                 windowLook = FrontWindow();
  178.             }
  179.             else
  180.                 windowLook=(WindowPtr)((WindowPeek)windowLook)->nextWindow;
  181.         }
  182.         SetPort(savePort);
  183.             
  184.     } else
  185.         theRect = *wRect;
  186.         
  187.     switch (windowClass) {
  188.         case kBaseWindow:
  189.             window = BaseMakeWindow(&theRect,title,visible,zoomDocProc,true);
  190.             break;
  191.         case kDrawWindow:
  192.             window = DrawMakeWindow(&theRect,title,visible,zoomDocProc,true);
  193.             break;
  194.         case kDrawMailerWindow:
  195.             window = DMailerMakeWindow(&theRect,title,visible,zoomDocProc,true);
  196.             break;
  197.         default:
  198.             DoError(kInternalError);
  199.     }
  200.     
  201.     return window;
  202. }
  203.  
  204.  
  205. /* sends a message to a given window */
  206.  
  207. void *SendWindowMessage(WindowPtr window,short msg,void *data)
  208. {
  209.     WInfoHndl infoHndl;
  210.     char hState;
  211.     MsgProc callProc;
  212.     void *theMsg;
  213.     
  214.     if (!IsAppWindow(window))
  215.         return nil;
  216.     
  217.     infoHndl = GetWindowInfo(window);
  218.     hState = HGetState((Handle) infoHndl);
  219.     HLock((Handle) infoHndl);
  220.     
  221.     switch (msg) {
  222.         case kIdleMessage:
  223.             callProc = (**infoHndl).m_idle;
  224.             break;
  225.         case kFixCursorMessage:
  226.             callProc = (**infoHndl).m_fixCursor;
  227.             break;
  228.         case kActivateMessage:
  229.             callProc = (**infoHndl).m_activate;
  230.             break;
  231.         case kDeactivateMessage:
  232.             callProc = (**infoHndl).m_deactivate;
  233.             break;
  234.         case kUpdateMessage:
  235.             callProc = (**infoHndl).m_update;
  236.             break;
  237.         case kKeyMessage:
  238.             callProc = (**infoHndl).m_key;
  239.             break;
  240.         case kResizeMessage:
  241.             callProc = (**infoHndl).m_resize;
  242.             break;
  243.         case kClickMessage:
  244.             callProc = (**infoHndl).m_click;
  245.             break;
  246.         case kDestroyMessage:
  247.             callProc = (**infoHndl).m_destroy;
  248.             break;
  249.         case kUndoMessage:
  250.             callProc = (**infoHndl).m_undo;
  251.             break;
  252.         case kCutMessage:
  253.             callProc = (**infoHndl).m_cut;
  254.             break;
  255.         case kCopyMessage:
  256.             callProc = (**infoHndl).m_copy;
  257.             break;
  258.         case kPasteMessage:
  259.             callProc = (**infoHndl).m_paste;
  260.             break;
  261.         case kClearMessage:
  262.             callProc = (**infoHndl).m_clear;
  263.             break;
  264.         case kPrintMessage:
  265.             callProc = (**infoHndl).m_print;
  266.             break;
  267.         case kPageSetupMessage:
  268.             callProc = (**infoHndl).m_pageSetup;
  269.             break;
  270.         case kSaveMessage:
  271.             callProc = (**infoHndl).m_save;
  272.             break;
  273.         case kLoadMessage:
  274.             callProc = (**infoHndl).m_load;
  275.             break;
  276.         case kEventMessage:
  277.             callProc = (**infoHndl).m_event;
  278.             break;
  279.         case kHitControlMessage:
  280.             callProc = (**infoHndl).m_ctrlHit;
  281.             break;
  282.         case kSelectAllMessage:
  283.             callProc = (**infoHndl).m_selectAll;
  284.             break;
  285.         case kGroupMessage:
  286.             callProc = (**infoHndl).m_group;
  287.             break;
  288.         case kUnGroupMessage:
  289.             callProc = (**infoHndl).m_unGroup;
  290.             break;
  291.         default:
  292.             return nil;
  293.     }
  294.     
  295.     if (callProc)
  296.         theMsg = (*callProc)(window,*infoHndl,data);
  297.     
  298.     HSetState((Handle) infoHndl,hState);
  299.     return theMsg;
  300. }
  301.  
  302.  
  303.